<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>

<!-- http://localhost/phplearn/javascript/function/%E5%8F%98%E9%87%8F%E4%BD%9C%E7%94%A8%E5%9F%9F.html
 -->
<script >
 
 
 //局部作用域
 
function foo() {
    for (var i=0; i<100; i++) {
        //
    }
    i += 100; // 仍然可以引用变量i
    alert(i)
}
foo() ;
/* let : 
function foo() {
    var sum = 0;
    for (let i=0; i<100; i++) {
        sum += i;
    }
    i += 1; // SyntaxError
}
*/

 
 
</script>


<body>








</body>
</html>